﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp5
{
    public partial class TeacherForm : Form
    {
        public TeacherForm()
        {
            InitializeComponent();
        }

        private void TeacherForm_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = WJNDBEntities.dbhelp.Teacher.ToList();
            this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.ReadOnly = true;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
                Teachers.Add f = new Teachers.Add();
                f.ShowDialog();
                dataGridView1.DataSource = WJNDBEntities.dbhelp.Teacher.ToList();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            int i = dataGridView1.CurrentCell.ColumnIndex;
            int j = dataGridView1.CurrentCell.RowIndex;
            string tid = Convert.ToString(dataGridView1[0, j].Value).Trim();
            DialogResult MsgBoxResult;//设置对话框的返回值
            MsgBoxResult = MessageBox.Show("是否要删除选定行:教师编号为——" + tid + " 的第" + (j + 1) + "行内容？",
            "提示",//对话框的标题
            MessageBoxButtons.YesNo,//定义对话框的按钮，这里定义了YSE和NO两个按钮
            MessageBoxIcon.Question,//定义对话框内的图表式样，这里是一个黄色三角型内加一个感叹号
            MessageBoxDefaultButton.Button2);
            if (MsgBoxResult == DialogResult.Yes)
            {
                Teacher t = WJNDBEntities.dbhelp.Teacher.Where(o => o.Tid == tid).FirstOrDefault();
                try
                {
                    WJNDBEntities.dbhelp.Teacher.Remove(t);
                    WJNDBEntities.dbhelp.SaveChanges();
                    MessageBox.Show("删除成功！");
                }
                catch
                {
                    MessageBox.Show("删除失败！");
                }
            }
            dataGridView1.DataSource = WJNDBEntities.dbhelp.Teacher.ToList();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            Teachers.Change f = new Teachers.Change();
            f.StartPosition = FormStartPosition.CenterParent;
            f.ShowDialog();
        }
    }
}
